#ifndef _ZERO_TEST_CORBATEST_H
#define _ZERO_TEST_CORBATEST_H
#include "include/cxxstd.h"
#include "include/corba.h"
#include "include/config.h"

using namespace zero;

namespace zerotest
{
struct TestResult
{
	int clientCallTrace;
	int serverCallTrace;

	// client >> server.
	long long clientOutput;
	long long serverInput;
	// server >> client.
	long long serverOutput;
	long long clientInput;

	long long serverExInput;
	long long clientExCatch;
};

// idl HelloWorld <([{
// idl prototype:
// 1) struct Message { char c; short s };
// 2) long HelloWorld::hello(inout Message a, in char b);
struct Message
{
	char c;
	short s;
};

class MessageTypeInfo : virtual public StaticTypeInfo
{
	public:
		MessageTypeInfo() {}
		virtual ~MessageTypeInfo() {}

		virtual std::size_t getLength() {
			return tiChar.getLength() + tiShort.getLength();
		}

		virtual void marshal(DataEncoder& out, void* v) {
			Message* m = static_cast<Message*>(v);
			out.struct_begin();
			tiChar.marshal(out, &m->c);
			tiShort.marshal(out, &m->s);
			out.struct_end();
		}
		virtual void demarshal(DataDecoder& in, void* v) {
			Message* m = static_cast<Message*>(v);
			in.struct_begin();
			tiChar.demarshal(in, &m->c);
			tiShort.demarshal(in, &m->s);
			in.struct_end();
		}
};

class WorldException : public Exception, virtual public StaticTypeInfo
{
	public:
		WorldException() : code(0) {}
		WorldException(int v) : code(v) {}
		WorldException(const WorldException& v) : code(v.code) {}

		virtual std::size_t getLength() { return tiLong.getLength(); }
		virtual void marshal(DataEncoder& out, void* v) {
			tiLong.marshal(out, &code);
		}
		virtual void demarshal(DataDecoder& in, void* v) {
			tiLong.demarshal(in, &code);
		}

		int getCode() { return code; }

	private:
		int code;
};

class SessionException : public Exception, virtual public StaticTypeInfo
{
	public:
		SessionException() {}
		SessionException(const SessionException& v) {}

		virtual std::size_t getLength() { return 0; }
		virtual void marshal(DataEncoder&, void*) {}
		virtual void demarshal(DataDecoder&, void*) {}
};

interface HelloWorld
{
	public:
		virtual long hello(Message&, char) throw (SessionException, WorldException) = 0;
};
// }])>
} // namespace zerotest
#endif
// vim: foldmarker=<([{,}])> foldmethod=marker
